function checkLocation(seq) {
	
	str     = eval('document.finishedGoodsForm.select_'+seq+'.checked');	
	var cnt = document.finishedGoodsForm.count.value;
	var maxVal = 0;
	if(cnt!=1)
	{		 
		if(str==false)
		{
			document.finishedGoodsForm.priority[seq].disabled=true;
			// added to set the default priority by ravikanth
			maxVal =  document.finishedGoodsForm.priority[seq].value;
			for ( var y =0 ; y < cnt ; y++ )
			{
				temp   = document.finishedGoodsForm.priority[y].value;
				if( temp > maxVal && maxVal != 0)
				{
					document.finishedGoodsForm.priority[y].value = parseInt(document.finishedGoodsForm.priority[y].value) -1;
				}
			}

			document.finishedGoodsForm.priority[seq].value='';
		}
		if(str==true)
		{
			document.finishedGoodsForm.priority[seq].disabled=false;
			// added to set the default priority by ravikanth
			for ( var y =0 ; y < cnt ; y++ )
			{
				temp   = document.finishedGoodsForm.priority[y].value;
				if( temp > maxVal)
				{
					maxVal = temp
				}
			}		
			document.finishedGoodsForm.priority[seq].value= parseInt(maxVal)+1 ;
		}
	}
	else
	{
		if(str==false)
		{
			document.finishedGoodsForm.priority.disabled=true;
			document.finishedGoodsForm.priority.value='';
		}
		if(str==true)
		{
			document.finishedGoodsForm.priority.disabled=false;
			document.finishedGoodsForm.priority.value=1;
		}
	}
}

function whileLoad()
{
	
	var cnt = document.finishedGoodsForm.count.value;
	if(cnt==1)
	{ 
		str     = eval('document.finishedGoodsForm.select_0.checked');
		if(str==false){
		document.finishedGoodsForm.priority.disabled=true;
		}
		if(str==true){
		document.finishedGoodsForm.priority.disabled=false;
		}

	}


	else{

	for(var i=0;i<cnt;i++){
				str     = eval('document.finishedGoodsForm.select_'+i+'.checked');
				if(str==false){
				document.finishedGoodsForm.priority[i].disabled=true;
				}
			    else if(str==true){
				document.finishedGoodsForm.priority[i].disabled=false;
				}
	}

	}
	
		
}



function saveFinishedGoods()
{
	
	var cnt						= document.finishedGoodsForm.count.value;
	var pa						= document.getElementById("message");
	var min_Level				= document.finishedGoodsForm.minLevel.value;
	var max_Level				= document.finishedGoodsForm.maxLevel.value;
	var re_oreder_level         = document.finishedGoodsForm.reorderLevel.value;
	var vendorPriority			=  null;

	// Added by hareesh on 14th July 2003
	// Chaned by harees on 26th August 2003
	// -- START --
	    //var mftPartNumber = document.finishedGoodsForm.mftPartNumber.value;
        //document.finishedGoodsForm.productName.value = mftPartNumber;
        var partNumber = document.finishedGoodsForm.productName.value;
        document.finishedGoodsForm.mftPartNumber.value = partNumber;
        //alert(document.finishedGoodsForm.mftPartNumber.value);
    // -- END --

	var vendorCnt				= 0;

	// added by ravikanth on 30-Sep-2003

	if(trim(document.finishedGoodsForm.productName.value)=='')
	{
		pa.innerHTML = "Manufacturing Part No cannot be null or contain spaces ";	
		document.finishedGoodsForm.productName.value = '';
		document.finishedGoodsForm.productName.focus();
		return;
	}
	else
	{
		document.finishedGoodsForm.productName.value = document.finishedGoodsForm.productName.value.trim();
	}


	if(trim(document.finishedGoodsForm.mktPartNumber.value)=='')
	{
		pa.innerHTML = "Marketing part No cannot be null or contain spaces ";	
		document.finishedGoodsForm.mktPartNumber.value = '';
		document.finishedGoodsForm.mktPartNumber.focus();
		return;
	}

	if( typeof document.finishedGoodsForm.locationName.length == 'undefined' )
	{
		if ( document.finishedGoodsForm.select_0.checked+"" == "true" )
		{
			vendorCnt++;
		}
		
		if( vendorCnt > 0 && ( document.finishedGoodsForm.priority.value =='0' || document.finishedGoodsForm.priority.value.trim().length == 0 ) )
		{
			pa.innerHTML = "Priority cannot 0 or empty ";	
			document.finishedGoodsForm.priority.value='';
			document.finishedGoodsForm.priority.focus();
			return; 
		}
	}
	else
	{
		vendorPriority = new Array(document.finishedGoodsForm.locationName.length);

		for (var x=0 ; x < document.finishedGoodsForm.locationName.length ; x++ )
		{
			var temp = eval("document.finishedGoodsForm.select_"+x);

			if( temp.checked+"" == "true" )
			{
				vendorCnt++;
				if (document.finishedGoodsForm.priority[x].value == 0 || document.finishedGoodsForm.priority[x].value.trim().length == 0 )
				{
					
					pa.innerHTML = "Vendor priority cannot 0 or empty ";	
					document.finishedGoodsForm.priority[x].value = '';
					document.finishedGoodsForm.priority[x].focus();
					return; 
				}
				vendorPriority[x] = document.finishedGoodsForm.priority[x].value
			}
		}
	}

	if( vendorCnt == 0)
	{
		pa.innerHTML = "Should select atleast one vendor";	
		return; 
	}

	if( vendorCnt > 1 )
	{
		for ( y=0 ; y < vendorPriority.length -1 ; y++ )
		{
			for ( z = y+1 ; z < vendorPriority.length ; z++ )
			{
				if( vendorPriority[y] != null && vendorPriority[z] != null && vendorPriority[y] != 0 && vendorPriority[z] !=0 )
				{
					if ( vendorPriority[z] == vendorPriority[y])
					{
						pa.innerHTML = "Two vendor priorities cannot be same ";	
						return; 
					}
				}
			}
		}
	}

	var flag = checkDupInProduct(document.finishedGoodsForm.productName,document.finishedGoodsForm.dupProductName);
	if( flag != -1 )
	{
		if( typeof document.finishedGoodsForm.dupProductName.length == 'undefined' )
		{
			document.finishedGoodsForm.dupProductName.focus();
		}
		else
		{
			document.finishedGoodsForm.dupProductName[flag].focus();	
		}
		pa.innerHTML = "Two Part numbers cannot be same";	
		return; 
	}
	if(re_oreder_level!=''){
		if (!isInteger(re_oreder_level)){
		pa.innerHTML = "Please enter valid Re Order Level,It must be number";	
		document.finishedGoodsForm.reorderLevel.select();
		document.finishedGoodsForm.reorderLevel.focus();
		return;
		}
	}
	else
	{
		pa.innerHTML = "Please enter Re Order Level";	
		document.finishedGoodsForm.reorderLevel.focus();
		return; 
	}
	
	if(min_Level!=''){
		if (!isInteger(min_Level)){
		pa.innerHTML = "Please enter valid Min Level,It must be number";	
		document.finishedGoodsForm.minLevel.select();
		document.finishedGoodsForm.minLevel.focus();
		return;
		}
	}
	else
	{
		pa.innerHTML = "Please enter Min Level";
		document.finishedGoodsForm.minLevel.focus();
		return; 
	}

	if(max_Level!=''){
		if(!isInteger(max_Level)){	
 	    pa.innerHTML = "Please enter valid Max Level,It must be number";
		document.finishedGoodsForm.maxLevel.select();
		document.finishedGoodsForm.maxLevel.focus();
		return;
		}	
	}
	else
	{
		pa.innerHTML = "Please enter Max Level";	
		document.finishedGoodsForm.maxLevel.focus();
		return; 
	}

	
	
	if(cnt==1)
	{ 
		str     = eval('document.finishedGoodsForm.select_0.checked');
		
				if(str==true){
                var priority		= document.finishedGoodsForm.priority.value;
				
				if(priority!=''){
				if (!isInteger(priority)){
				pa.innerHTML = "Please enter valid Priority,It must be number";
				document.finishedGoodsForm.priority.select();
				document.finishedGoodsForm.priority.focus();
				return;
				}
				}

				

			}

	}


	else{
		
	for(var i=0;i<cnt;i++){
			
				str     = eval('document.finishedGoodsForm.select_'+i+'.checked');
				
				if(str==true){
				var priority		= document.finishedGoodsForm.priority[i].value;
				if(priority!=''){
				if (!isInteger(priority)){
				pa.innerHTML = "Please enter valid Priority,It must be number";
				document.finishedGoodsForm.priority[i].select();
				document.finishedGoodsForm.priority[i].focus();
				return;
				}
				}				
				}
				
	}

	}
	

	if(cnt!=1){
	for(var i=0;i<cnt;i++){
				document.finishedGoodsForm.priority[i].disabled=false;
				document.finishedGoodsForm.locationName[i].disabled=false;
	}
	}

	else{
		document.finishedGoodsForm.priority.disabled=false;
		document.finishedGoodsForm.locationName.disabled=false;
	    }
	 document.finishedGoodsForm.submit();
		
}


function checkValuesForBoardMaking()
{
    var cnt = document.finishedGoodsForm.count.value;
    var pa  = document.getElementById("message");

    if(cnt==1)
    { 
	str = eval('document.finishedGoodsForm.select_0.checked');
		
	if(str==true){
               var priority = document.finishedGoodsForm.priority.value;
				
		if(priority!=''){
                    if (!isInteger(priority)){
			pa.innerHTML = "Please enter valid Priority,It must be number";
			document.finishedGoodsForm.priority.select();
			document.finishedGoodsForm.priority.focus();
			return false;
                    }
		} else {
                    pa.innerHTML = "Please enter Priority,It must be number";
                    document.finishedGoodsForm.priority[i].select();
                    document.finishedGoodsForm.priority[i].focus();
                    return false;
                }

	}

    }
    else
    {
		
        for(var i=0;i<cnt;i++){
		str = eval('document.finishedGoodsForm.select_'+i+'.checked');
				
		if(str==true){
                    var priority = document.finishedGoodsForm.priority[i].value;
                    if(priority!=''){
			if (!isInteger(priority)){
                        	pa.innerHTML = "Please enter valid Priority,It must be number";
				document.finishedGoodsForm.priority[i].select();
				document.finishedGoodsForm.priority[i].focus();
				return false;
			}
                    } else {
                        pa.innerHTML = "Please enter Priority,It must be number";
				document.finishedGoodsForm.priority[i].select();
				document.finishedGoodsForm.priority[i].focus();
				return false;
                    }
		}
	}

    }
	

    if(cnt!=1){
	for(var i=0;i<cnt;i++){
				document.finishedGoodsForm.priority[i].disabled=false;
				document.finishedGoodsForm.locationName[i].disabled=false;
	}
    }
    else
    {
	document.finishedGoodsForm.priority.disabled=false;
	document.finishedGoodsForm.locationName.disabled=false;
    }
    
    return true;
}